<template>
  <div class="home-like yh-layout-box">
    <div class="rolls-head">
      <h3>猜您喜欢</h3>
      <p>智能推荐 轻松采购</p>
      <span class="new-items" @click="newItem()">换一批</span>
    </div>
    <div :class="likeActive?'like-rolls rolls-active':'like-rolls'" >
      <!-- <a class="rolls-item" v-for="i in list" :href="URL.mall+'/product/detail?id='+ i.productId" target="_blank"> -->
      <a class="rolls-item" v-for="i in list" @click="routeToPath('/product/'+ i.productId, 'mallplus', 'new')">
        <div class="item-pic cursor">
          <img class="maxs" :src="URL.PIC+i.productImg" :alt="i.productTitle">
        </div>
        <div class="item-title">{{ i.productTitle }}</div>
        <div class="item-price">
          ￥{{ i.productPrice }}
        </div>
      </a>
    </div>
  </div>
</template>

<script>
import { getLikeList } from '@/api/home'
export default {
  data() {
    return {
      list: [],
      listQuery: {
        categoryIds: [],
        page: 1,
        size: 5,
      },
      likeActive: false,
    }
  },
  created(){
    this.getLikeList();
  },
  methods: {
    // 获取猜您喜欢商品
    getLikeList() {
      this.likeActive = true;
      getLikeList(this.listQuery).then(res=>{
        setTimeout(()=>{
          this.list = res.data.list;
          this.likeActive = false;
        }, 300)

      })
    },
    // 获取切换商品
    newItem() {
      if(this.listQuery.page < 10){
        this.listQuery.page++
      }else{
        this.listQuery.page = 1
      }
      this.getLikeList();
    }
  }
}
</script>

<style lang="scss" scoped>
.home-like{
  overflow: hidden;
}
.like-rolls{
  opacity: 1;
}
.rolls-item{
  border-radius: 10px;
  width: 210px;
  float: left;
  margin-left: 37px;
  margin-bottom: 10px;
  padding-top: 0;
  padding-bottom: 20px;
  text-decoration: none;
  .item-pic{
    width: 210px;
    height: 210px;
    margin-bottom: 20px;

    img{
      border-radius: 8px;
      transition: all 0.4s;
    }
    &:hover img{
      box-shadow: 0 12px 36px rgba(0,0,0,0.1)
    }
  }
  .item-title{
    font-size: 14px;
    color: #333;
    padding-left: 10px;
    padding-right: 10px;
    line-height: 20px;
    height: 40px;
    text-align: center;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    letter-spacing: 1px;
  }
  .item-price{
    text-align: center;
    color: #D0021B;
    margin-top: 12px;
  }
}
.rolls-active{
  opacity: .7;
  transition: all .5s;
}
.rolls-item:nth-child(1){
  margin-left: 0;
}
.rolls-head{
  position: relative;
  h3{
    font-size: 30px;
    color: #333;
    text-align: center;
    font-weight: 500;
    padding-bottom: 0;
    margin-top: 0;
    margin-bottom: 0;
  }
  p{
    color: #999999;
    text-align: center;
    margin-bottom: 16px;
  }
  .new-items{
    position: absolute;
    right: 0;
    bottom: 0;
    color: #999999;
    cursor: pointer;
    &:hover{
      color: #255b8b
    }
  }
}
</style>
